/*
1、绝不要返回 pointer 或reference指向一个local stack对象，或返回 reference 指向一个 heap-allocated 对象，
或返回pointer 或reference 指向一个 local static 对象而有可能同时需要多个这样的对象。
*/

#include<iostream>

class Rational
{
public:
    Rational(int a = 0,int b = 1):a(a),b(b){};
    friend const Rational operator*(const Rational &a,const Rational &b);
    friend std::ostream& operator<<(std::ostream &a,const Rational &b);
private:
    int a, b;
};

//必须要返回一个对象，返回指针没法处理好释放问题，引用就是引用局部变量的地址，如果使用static的话会有其他问题：（a*b）始终等于(c*d)
const Rational operator*(const Rational &a,const Rational &b)
{
    return (Rational((a.a) * (b.a),a.b * b.b));
}

std::ostream& operator<<(std::ostream &a,const Rational &b)
{
    a << b.a << "/" << b.b<<std::endl;
    return a;
}

int main(int argc, char const *argv[])
{
    Rational a(1,3);
    Rational b;
    b = a;

    Rational c = a * b;
    std::cout <<a<<b<<c;
    return 0;
}

